package com.Wheesper.www.WheesperServer.Model;
import java.util.ArrayList;
import java.util.function.Predicate;



public class Group implements Comparable<Group>{
	private Integer _id;
	private String _creator_email;
	private String _name;
	private String _intro;//群简介
	private Integer _member_num;
	private ArrayList<Member> _members;
	public class Member{
		private String _email;
		private String _nickname;
		
		public Member(String _email,String _nickname) {
			this._email = _email;
			this._nickname = _nickname;
		}
		public String Email() {
			return this._email;
		}
		public String Nickname() {
			return this._nickname;
		}
	}
	
	public Group(Integer _id,String creator_email) {
		this._id = _id;
		this._creator_email = creator_email;
		this._members = new ArrayList<Member>();
	}
	
	public Integer ID() {
		return this._id;
	}
	public String Name() {
		return this._name;
	}
	
	public void Name(String _name) {
		this._name = _name;
	}
	
	public String CreatorEmail() {
		return this._creator_email;
	}
	
	public String Intro() {
		return this._intro;
	}
	
	public void Intro(String intro) {
		this._intro = intro;
	}
	
	public ArrayList<Member> Members(){
		return this._members;
	}
	
	public Integer MemberNum(){
		return this._member_num;
	}
	
	public void addNewMember(String email,String nickname) {
		this._members.add(new Member(email,nickname));
		_member_num = _members.size();
	}
	
	public void removeOldMember(String email) {
		_members.removeIf(new Predicate<Member>() {
			@Override
			public boolean test(Member t) {
				if(t.Email() == email) {
					return true;
				}
				return false;
			}
		});
		_member_num = _members.size(); 
	}
	
	//解散该群
	public void dismiss() {
		//TODO:
	}

	@Override
	public int compareTo(Group o) {
		if(this.ID() > o.ID())
			return 1;
		else if (this.ID() <o.ID())
			return -1;
		return 0;
	}
}
